/* Common code for cleaners */

//Invoked when the other agent tells where the garbage is
+garbage(Garb)[source(Ag)] 
   :  Ag \== self
   <- .print("Received tell ",garbage(Garb)," from ", Ag);
      +garb(Garb).
   
+!finish : garb(A) <- -garb(A).
   
+garbageOffer(Garb)[source(Ag)] : myId(MyId) <-
      lookupArtifact("cleanAuction",CaId);
      focus(CaId);
      .println("I am gonna give an offer!");
      //Aqui inicia o leilão
      getDistance(MyId,Garb,Dist);
      .println("Distance for agent ", MyId, " to  ", Garb, " " , is, " ", Dist); 
      bid(Dist,MyId);
      !clearOffers.
      
+!clearOffers : garbageOffer(Garb)[source(Ag)]  <-
                   -garbageOffer(A)[source(Ag)];
     			   .print("Offer : ", A).
                                    
+!joinOrganization <- lookupArtifact("mypaper",GrId); 
      adoptRole(sweeper)[artifact_id(GrId)];
      //Papel para cuidar da tinta 
      adoptRole(clothpasser)[artifact_id(GrId)];
      focus(GrId);
      .print("I joined the organization");
      +ready.
      
+!kqml_received(Sender, askOne, ready, ReplyWith) : ready
   <- .send(Sender,tell,"Yes", ReplyWith);
      //adjusts the belief ready for the next auction
      -ready.
   
+!kqml_received(Sender, askOne, ready, ReplyWith) : not ready
   <- .send(Sender,tell,"No", ReplyWith). // send the answer

/* useful rules */

+!join 
   <- .my_name(Me); 
   	  .print("I joined workspace ora4mas"); 
      joinWorkspace("ora4mas",_).
-!join
   <- .wait(200);
      !!join.

// keep focused on schemes my groups are responsible for
+schemes(L)
   <- for ( .member(S,L) ) {
         lookupArtifact(S,ArtId);
         focus(ArtId)
      }.
      
+!quit_mission(M,S)
   <- .print("leaving my mission ",M," on ",S,"....");
      leaveMission(M)[artifact_name(S)].            
              